﻿@model TGBTech.Core.Models.ChungTu.Data
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />

@{
    ViewBag.Title = "Data";
}

<h3>Data</h3>

@using (Html.BeginForm("Index", "Data", FormMethod.Post, new { @class = "form-inline", role = "form" }))
{
    <p>
        @Html.TextBox("SearchString", null, new { @class = "form-control", placeholder = "Tìm kiếm", style = "margin-bottom:0px" })
        <input type="submit" value="Tìm kiếm" class="btn btn-default" />
    </p>
}

<div id="tableData">
    <table class="table" id="Data">
        <tr>
            <th>
                @Html.DisplayName("Số CT")
            </th>
            <th>
                @Html.DisplayName("Ngày CT")
            </th>
            <th>
                @Html.DisplayName("Nợ")
            </th>
            <th>
                @Html.DisplayName("Có")
            </th>
            <th>
                @Html.DisplayName("Diễn giải nợ")
            </th>
            <th>
                @Html.DisplayName("Diễn giải có")
            </th>
            <th>
                @Html.DisplayName("KH(Nợ)")
            </th>
            <th>
                @Html.DisplayName("KH (Có)")
            </th>
            <th>
                @Html.DisplayName("Số tiền")
            </th>
            <th>
                @Html.DisplayName("Số hiệu")
            </th>
            <th>
                @Html.DisplayName("Số hóa đơn")
            </th>
            <th>
                @Html.DisplayName("Ngày hóa đơn")
            </th>
            <th>
                @Html.DisplayName("Mặt hàng")
            </th>
            <th>
                @Html.DisplayName("VAT")
            </th>
            <th>
                @Html.DisplayName("Thuế suất")
            </th>

            <th></th>
        </tr>

        @foreach (var item in ViewBag.List)
        {
            <tr>
                <td>
                    @item.SoCT
                </td>
                <td>
                    @item.NgayCT.ToString("dd/MM/yyyy")
                </td>
                <td>
                    @item.TaiKhoanNoId
                </td>
                <td>
                    @item.TaiKhoanCoId
                </td>
                <td>
                    @item.DienGiaiNo
                </td>
                <td>
                    @item.TaiKhoanCo.Name
                </td>

                @if (@item.KhachHangId != "None")
                {
                    if (@item.LoaiKH == true)
                    {
                        <td>@item.KhachHangId</td>
                        <td></td>
                    }
                    else
                    {
                        <td></td>
                        <td>@item.KhachHangId</td>
                    }
                }
                else
                {
                    <td></td>
                    <td></td>
                }


                @if (@item.SoTien != 0)
                {
                    <td>@item.SoTien.ToString("#,#.00#;(#,#.00#)")</td>
                }
                else
                {
                    <td></td>
                }

                <td>
                    @item.SoHieu
                </td>
                <td>
                    @item.SoHoaDon
                </td>
                <td>
                    @if (@item.NgayHoaDon != null)
                    {
                        @item.NgayHoaDon.ToString("dd/MM/yyyy")
                    }
                    else
                    {
                        @item.NgayHoaDon
                    }
                </td>
                <td>
                    @item.DanhMuc
                </td>

                @{var money = (Decimal)@item.VAT * @item.SoTien;}
                @if (@money != 0)
                {
                    <td>@money.ToString("#,#.00#;(#,#.00#)")</td>
                    <td>@(@item.VAT * 100)%</td>
                }
                else
                {
                    <td></td>
                    <td></td>
                }





                <td>
                    <a data-toggle="modal" class="btnEditData" id="@item.Id" href="#editData">Sửa</a>
                    |
                    <a data-toggle="modal" class="btnDeleteData" id="@item.Id" href="#editData">Xóa</a>
                </td>
            </tr>
        }
        <tr>
            <th>
                @Html.DisplayName("Số CT")
            </th>
            <th>
                @Html.DisplayName("Ngày CT")
            </th>
            <th>
                @Html.DisplayName("Nợ")
            </th>
            <th>
                @Html.DisplayName("Có")
            </th>
            <th>
                @Html.DisplayName("Diễn giải nợ")
            </th>
            <th>
                @Html.DisplayName("Diễn giải có")
            </th>
            <th>
                @Html.DisplayName("KH(Nợ)")
            </th>
            <th>
                @Html.DisplayName("KH (Có)")
            </th>
            <th>
                @Html.DisplayName("Số tiền")
            </th>
            <th>
                @Html.DisplayName("Số hiệu")
            </th>
            <th>
                @Html.DisplayName("Số hóa đơn")
            </th>
            <th>
                @Html.DisplayName("Ngày hóa đơn")
            </th>
            <th>
                @Html.DisplayName("Mặt hàng")
            </th>
            <th>
                @Html.DisplayName("VAT")
            </th>
            <th>
                @Html.DisplayName("Thuế suất")
            </th>

            <th></th>
        </tr>

    </table>
    <p>
        @using (Html.BeginForm("Create", "Data", FormMethod.Post, new { @class = "form-inline", id = "formAddData" }))
        {
            @Html.AntiForgeryToken()

            <hr />
            @Html.ValidationSummary(true)
            <div class="form-group" style="width:100px">
                <label>Chứng từ</label>

                @Html.TextBoxFor(model => model.SoCT, new { @class = "form-control", placeholder = "Số" })<br />
                @Html.TextBoxFor(model => model.NgayCT, new { @class = "form-control", placeholder = "Ngày" })<br />
            </div>

            <div class="form-group" style="width:250px">
                <label>Tài khoản</label>
                @Html.DropDownList("TaiKhoanNoId", null, "--Nợ--", new { @class = "form-control select2me" })<br />
                @Html.TextBoxFor(model => model.DienGiaiNo, new { @class = "form-control", placeholder = "Diễn giải nợ", style = "margin-top:10px" })<br />
                @Html.DropDownList("TaiKhoanCoId", null, "--Có--", new { @class = "form-control select2me" })<br />
            </div>


            <div class="form-group" style="width:300px">
                <label>Khách hàng</label>
                @Html.DropDownList("KhachHangId", null, "--Chọn--", new { @class = "form-control select2me", style = "margin-bottom:10px" })<br />
                <div>
                    <label>Khách hàng nợ</label><br />
                    @Html.EditorFor(model => model.LoaiKH)
                </div>


            </div>

            <div class="form-group" style="width:100px">
                <label>Số tiền</label>
                @Html.TextBoxFor(model => model.SoTien, new { @class = "form-control", placeholder = "Số tiền" })<br />
                @Html.TextBoxFor(model => model.VAT, new { @class = "form-control", placeholder = "VAT (10%)" })<br />
            </div>
            <div class="form-group" style="width:100px">
                <label>Hóa đơn</label>
                @Html.TextBoxFor(model => model.SoHieu, new { @class = "form-control", placeholder = "Số Seri" })<br />
                @Html.TextBoxFor(model => model.SoHoaDon, new { @class = "form-control", placeholder = "Số HĐ" })<br />
                @Html.TextBoxFor(model => model.NgayHoaDon, new { @class = "form-control", placeholder = "Ngày HĐ" })<br />
            </div>


            <div class="form-group" style="width:150px">
                <label>Mặt hàng</label>
                @Html.TextBoxFor(model => model.DanhMuc, new { @class = "form-control", placeholder = "Mặt hàng" })<br />
            </div>

            <div class="form-group" style="margin-top:25px">
                <input type="submit" value="Thêm" class="btn btn-default submit" />
            </div>

        }
        <hr />
    </p>
</div>

Page @(ViewBag.List.PageCount < ViewBag.List.PageNumber ? 0 : ViewBag.List.PageNumber) of @ViewBag.List.PageCount

@Html.PagedListPager((PagedList.IPagedList)ViewBag.List, page => Url.Action("Index",
    new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))

<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" id="editData">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Data</h4>
            </div>
            <div class="modal-body" id="bodyEditData"></div>
        </div>
    </div>
</div>